﻿<?php
include_once("../driver/drive.php");
include_once("../driver/tableLocation.php");
class messageWHandle
{
    private function insert_sql($array)
    {
        $tablename = tableLocation::messageTable();
        $sql = "insert into $tablename(";
        $first=0;
        foreach( $array as $key=>$value)
        {
            if($first==0)
            {
                $sql .= "$key";
                $first=1;
            }
            else
            {
                $sql .= ",$key";
            }
        }
        $sql .=")values(";
        $first=0;
        foreach( $array as $key=>$value)
        {
            if($first==0)
            {
                $sql .= "'$value'";
                $first=1;
            }
            else
            {
                $sql .= ",'$value'";
            }
        }
        $sql .= ")";
        echo $sql;
        return $sql;
    }
    public function insert_data($array)
    {
        $sql = $this->insert_sql($array);
        echo $sql;
        return drive::exc($sql);
    }
    public function update_message($array, $id)
    {
        $sqlk=array();
        foreach($array as $key=>$value)
        {
            array_push($sqlk," `$key`='$value' ");
        }
        $sqls = implode(",",$sqlk);
        $table = tableLocation::messageTable();
        $sql = "update $table set $sqls where id=$id";
        echo $sql;
        return drive::exc($sql);
    }
    public function delete_message($id)
    {
        $table = tableLocation::messageTable();
        $sql="delete from $table where id=$id";
        echo $sql;
        return drive::exc($sql);
    }

    public function delete_dead_message()
    {
        //删除那些发送和接收都删除的信息
        $table = tableLocation::messageTable();
        $sql="delete from $table where `sdelete`='1' and `rdelete`='1'";
        echo $sql;
        return drive::exc($sql);
    }
}
?>